#include<bits/stdc++.h>
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=1e6+5;
int n,k,ans;
int d[N],vis[N],dep[N],id[N];
vector<int>to[N];
void dfs(int x,int DEP){
	dep[x]=DEP;
	for(auto y:to[x]){
		if(vis[y])continue;
		dfs(y,DEP+1);
	}
}
void del(int x){
	vis[x]=1;
	for(auto y:to[x])
		if(!vis[y])del(y);
}
void sol(){
	if(d[1]!=1)ans++,d[1]=1;
	for(int i=2;i<=n;i++)to[d[i]].push_back(i);
	dfs(1,0);
	for(int i=1;i<=n;i++)id[i]=i;
	sort(id+1,id+n+1,[](int A,int B){return dep[A]>dep[B];});
	for(int i=1;i<=n;i++){
		int x=id[i];
		if(dep[x]<=k)break;
		if(vis[x])continue;
		ans++;
		for(int j=1;j<k;j++)x=d[x];
		del(x);
	}
}
int main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	read(n,k);
	for(int i=1;i<=n;i++)read(d[i]);
	sol();
	write(ans);
	flush();
	return 0;
}/*
11 2
2 1
2 2 2
3 3 4 4 5 5

*/
